// pswdwt.js
//   An example of input password checking, using the submit 
//   event
     
// The event handler function for password checking


function chkPasswords() { 
  var init = document.getElementById("initial");
  var sec = document.getElementById("second");
  if (init.value == "") {
    alert("You did not enter a password \n" +
          "Please enter one now");
    return false;
  }
  if (init.value != sec.value) {
    alert("The two passwords you entered are not the same \n" +
          "Please re-enter both now");
    return false;
  } else
    return true;
}
/*
  当第一个输入框失去焦点时
  检测第一个输入框是否输入，是则允许第二个输入
*/

function check1(){
  var pwd1 = document.getElementById('initial').value;
  //如果第一个不为空且失去焦点，允许第二个输入
  if(pwd1 !== ''){
    document.getElementById("second").removeAttribute("readonly");
    document.getElementById("second").addEventListener('blur',check2);
  }else{//为空，不允许第二个输入
    document.getElementById("second").setAttribute("readonly",true);
    document.getElementsByName('submit')[0].setAttribute("disabled",true);
  }
}

function check2(){
  var pwd2 = document.getElementById('second').value;
  if(pwd2 !== ''){
    document.getElementsByName('submit')[0].removeAttribute('disabled');
  }else{
    document.getElementsByName('submit')[0].setAttribute("disabled",true);
  }
}